#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define PRINT_ERR(msg) do{ \
        perror(msg);\
        return -1;\
    }while(0)
#include "myleds.h"
void led_blink(int fd,int cmd,int which,int delay)
{
    int ON[] = {CORE_LED_ON,EXTEND_LED_ON};
    int OFF[] = {CORE_LED_OFF,EXTEND_LED_OFF};
    ioctl(fd,ON[cmd],which);
    sleep(delay);
    ioctl(fd,OFF[cmd],which);
    sleep(delay);
}
int main(int argc,const char * argv[])
{
    int fd;
    if((fd = open("/dev/myleds",O_RDWR))==-1)
        PRINT_ERR("open myleds error");

    while(1){
        led_blink(fd,CORE,0,1);
        led_blink(fd,CORE,1,1);
        led_blink(fd,CORE,2,1);
        led_blink(fd,EXTEND,0,1);
        led_blink(fd,EXTEND,1,1);
        led_blink(fd,EXTEND,2,1);
    }
    close(fd);
    return 0;
}